package com.fadada.api;



import com.fasc.open.api.bean.base.BaseRes;
import com.fasc.open.api.bean.common.*;
import com.fasc.open.api.bean.res.service.AccessTokenRes;
import com.fasc.open.api.client.OpenApiClient;
import com.fasc.open.api.client.ServiceClient;
import com.fasc.open.api.exception.ApiException;
import com.fasc.open.api.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author FDD
 * @version 0.0.1
 * @ClassName BaseDemo.java
 * @Description 基础类demo
 * @Param
 * @createTime 2021年09月22日 15:36:00
 */
public class BaseDemo {
    public static Logger log = LoggerFactory.getLogger(BaseDemo.class);
    public static String APPID = "appId值";
    public static String APPSECRET = "appSecret值";
    public static String SERVERURL = "服务请求地址";
    public static OpenApiClient openApiClient;
    public static String accessToken = "accessToken值";
    public static String openCorpId = "企业id";
    public static String openUserId = "个人id";



    /**
     * 初始化客户端
     *
     * @return
     */
    public OpenApiClient getClient() {
        return new OpenApiClient(APPID, APPSECRET, SERVERURL);
    }

    /**
     * 获取应用accessToken
     *
     * @return
     * @throws Exception
     */
    public String getAccessToken(OpenApiClient openApiClient) throws ApiException {
        ServiceClient serviceClient= new ServiceClient(openApiClient);
        BaseRes<AccessTokenRes> res = serviceClient.getAccessToken();
        ResultUtil.printLog(res, openApiClient.getJsonStrategy());
        return res.getData().getAccessToken();
    }

    public static Actor getActor(String actorType, String actorId, String actorIdentType, ActorUser actorUser, ActorCorp actorCorp,Notification notification) throws ApiException{
        Actor actor = new Actor();
        //参与方类型：1: 填写方 2: 签署方 3: 抄送方。
        actor.setActorType(actorType);
        //参与方标识。在同一个签署任务中，同类型的各参与方标识不可重复。
        //例如：- 通用标识：甲方、乙方、丙方 - 金融场景：借款人、贷款人、担保人 - 供应链场景：核心企业、供应商 ...
        actor.setActorId(actorId);
        //参与方主体类型： 1: 个人 2: 企业
        actor.setActorIdentType(actorIdentType);
        //个人用户参与方信息。和actorCorp必须二选一必填，且和actorIdentType一致。
        actor.setActorUser(actorUser);
        //企业参与方信息。和actorUser必须二选一必填，且和actorIdentType一致。
        actor.setActorCorp(actorCorp);
        //定义是否及如何向该参与方发送通知。默认不通知，需要设置属性Notification.sendNotification=false。
        actor.setNotification(notification);
        return actor;
    }

    public static ActorUser getActorUser(String openUserId) throws ApiException{
        ActorUser actorUser = new ActorUser();
        actorUser.setActorUserId(openUserId);
        return actorUser;
    }

    public static ActorCorp getActorCorp(String openCorpId,String operatorId) throws ApiException{
        ActorCorp actorCorp = new ActorCorp();
        actorCorp.setActorCorpId(openCorpId);
        actorCorp.setOperatorId(operatorId);
        return actorCorp;
    }
}
